#include <mzfc_inc.h>
#include <mzfc/SipHelper.h>

class MySingleLineEdit : public UiSingleLineEdit
{

private:

	DWORD m_sipMode;

public:

	MySingleLineEdit()
	{
		m_sipMode = IM_SIP_MODE_KEEP;
	}

	void SetSipMode(DWORD dwMode, DWORD dwSipOffset = 0xffffffff)
	{
		m_sipMode = dwMode;

		UiSingleLineEdit::SetSipMode(dwMode, dwSipOffset);
	}

protected:

	virtual void OnFocused(UiWin* pWinPrev)
	{
		UiSingleLineEdit::OnFocused(pWinPrev);

		RECT rect1 = GetRect();
		RECT rect2 = MzGetVisibleDesktopRect();

		UiWin* parent = GetParent();

		int fix = 0;

		if(m_sipMode == IM_SIP_MODE_DIGIT)
		{
			g_IsNumberSipOpen = true;

			fix = 77;
		}
		else
		{
			g_IsNumberSipOpen = false;
		}

		if(parent->GetPosY() + rect1.bottom + SETTINGWIN_TB_GAP - fix > RECT_HEIGHT(rect2))
		{
			parent->SetPos(parent->GetPosX(), -(rect1.bottom + SETTINGWIN_TB_GAP - fix - RECT_HEIGHT(rect2)), parent->GetWidth(), parent->GetHeight());

			parent->Invalidate();
		}
	}

	virtual void OnLostFocus(UiWin* pWinNext)
	{
		UiSingleLineEdit::OnLostFocus(pWinNext);

		g_IsNumberSipOpen = false;

		if(MzIsSipOpen() == false)
		{
			UiWin* parent = GetParent();

			if(parent->GetPosY() != MZM_HEIGHT_CAPTION)
			{
				parent->SetPos(parent->GetPosX(), MZM_HEIGHT_CAPTION, parent->GetWidth(), parent->GetHeight());

				parent->Invalidate();
			}
		}
	}
};